import time
from rpyc import Service
from rpyc.utils.server import ThreadedServer

## from top.wardyan.core.vo.vos import Record
from top.wardyan.core.vo.vos import *

import json


def todict(obj) :
    return obj.__dict__

class TestService(Service) :
    def exposed_get_time(self) :
        return time.ctime()

    def exposed_script_list(self, key = "")  :
        data : list[Record] = []
        ## r : Record = Record()
        # r.set("name", "n1")
        # r.set("age", "2")
        # r.set("school", "??")
        # data.append(r)
        # data.append(r)
        # data.append(r)
        # data.append(r)
        # data.append(r)
        ## ID 模块 名称 说明 负责人 创建日期 最后修改日期 脚本说明 备注
        r : Record = Record()
        r.set("ID","ID")
        r.set("Model","模块")
        r.set("Name","名称")
        r.set("Descript","说明")
        r.set("Author","负责人")
        r.set("CreateDate","创建日期")
        r.set("UpdateDate","最后修改日期")
        r.set("Remark","脚本说明")
        r.set("Note","备注")
        data.append(r)


        r : Record = Record()
        r.set("ID",1)
        r.set("Model","现场生产")
        r.set("Name","kp_device_view")
        r.set("Descript","设备管理")
        r.set("Author","负责人")
        r.set("CreateDate","2024-03-03 22:25:59.012")
        r.set("UpdateDate","2024-03-03 22:25:59.012")
        r.set("Remark","请勿修改")
        r.set("Note","无")
        data.append(r)

        r : Record = Record()
        r.set("ID",2)
        r.set("Model","基础资料")
        r.set("Name","zp_empl_view")
        r.set("Descript","人员档案")
        r.set("Author","系统")
        r.set("CreateDate","2024-03-03 22:25:59.012")
        r.set("UpdateDate","2024-03-03 22:25:59.012")
        r.set("Remark","")
        r.set("Note","")
        data.append(r)

        r : Record = Record()
        r.set("ID",3)
        r.set("Model","基础资料")
        r.set("Name","zp_dept_view")
        r.set("Descript","部门资料")
        r.set("Author","系统")
        r.set("CreateDate","2024-03-03 22:25:59.012")
        r.set("UpdateDate","2024-03-03 22:25:59.012")
        r.set("Remark","")
        r.set("Note","")
        data.append(r)
        
        r : Record = Record()
        r.set("ID",4)
        r.set("Model","基础资料")
        r.set("Name","zp_machine_view")
        r.set("Descript","织机")
        r.set("Author","系统")
        r.set("CreateDate","2024-03-03 22:25:59.012")
        r.set("UpdateDate","2024-03-03 22:25:59.012")
        r.set("Remark","")
        r.set("Note","")
        data.append(r)
        ## json_str = json.dumps(data, default=todict)
        json_str = recordstojsonsr(data)
        return json_str
if __name__ == "__main__" : 
    s = ThreadedServer(TestService, port = 8899)
    s.start()